package com.zhkj.txg.module.home.adapter

import android.view.View
import android.widget.ImageView
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.zhkj.lib.utils.ScreenUtil
import com.zhkj.txg.R
import com.zhkj.txg.module.home.entity.ShopCateEntity
import com.zhkj.txg.module.home.ui.ProductListActivity
import com.zhkj.txg.utils.ImageUtils

class ShopHomeCateAdapter :
    BaseQuickAdapter<ShopCateEntity, BaseViewHolder>(R.layout.item_shop_cate) {
    var shopId: Int = 0

    init {
        setOnItemClickListener { _, _, position ->
            val shopCate = data[position]
            ProductListActivity.shopOpen(context, shopCate.name, shopId, shopCate.id)
        }
    }

    override fun convert(helper: BaseViewHolder, item: ShopCateEntity) {
        val imageView = helper.setText(R.id.tvCate, item.name).getView<ImageView>(R.id.ivCate)
        ImageUtils.loadCircleImage(context, imageView, item.image)
    }

    override fun onItemViewHolderCreated(viewHolder: BaseViewHolder, viewType: Int) {
        viewHolder.getView<View>(R.id.root).layoutParams.width = ScreenUtil.getScreenWidth(context) / 4
    }
}